package com.resource.authoritymanage.config;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

//用户权限枚举类
@Getter
@AllArgsConstructor
public enum UserPrivilegeEnum {
    CONSUMER_PRIVILEGE("0","游客权限"),
    STUDENT_PRIVILEGE("1","学生权限"),
    TEACHER_PRIVILEGE("2","教师权限");

    private String code;
    private String name;


    public static String parseName(Integer code){
        Optional<String> optional = Arrays.stream(values()).filter(item -> Objects.equals(code, item.getCode())).findFirst()
                .map(item -> item.getName());
        return optional.isPresent() ? optional.get() : null;}

    public static String parseCode(String name){
        Optional<String> optional = Arrays.stream(values()).filter(item -> Objects.equals(name, item.getName())).findFirst()
                .map(item -> item.getCode());
        return optional.isPresent() ? optional.get() : null;}
}
